import React, { useEffect,useState } from 'react';
import {  Button, Table, Switch, } from 'antd'
import { useNavigate } from 'react-router-dom';
import TimeList from "../../components/chen/TimeList";
import '../../styles/chen/systemdrug.scss'
import * as service from  '../../api/chen/index'
interface Props{

}
function SystemDrug(props: Props) {
  var navigate=useNavigate()
    const [data,setData]=useState([])

  //   const data = [
  //       {
  //        id: '1',
  //        pic:'',
  //         drugtitle: 'John Brown',
  //         drugkind:'非处方药',
  //         person: "李明明",
  //         pbulishStasus:'已发布',
  //         collaction:'130',
  //         endingtime: 'New York No. 1 Lake Park',
            
  //           description:''
  //       },
  //       {

  //        id: '2',
  //        pic:'',
  //         drugtitle: 'Jim Green',
  //         drugkind:'非处方药',
  //       person: "李明明",
  //       pbulishStasus:'已发布',
  //       collaction:'130',
              
  //         endingtime: 'London No. 1 Lake Park',
         
  //         description:''
  //       },
  //       {
  //        id: '3',
  //        pic:'',
  //         drugtitle: 'Joe Black',
  //         drugkind:'非处方药',
  //         person: "李明明",
  //         pbulishStasus:'已发布',
  //         collaction:'130',
  //         endingtime: 'Sidney No. 1 Lake Park',
          
  //           description:''
  //       },
  // ];
  useEffect(() => {
    service.drug_list().then(res => {
      console.log(res)
      setData(res.data)
    })
  }, [])
  const myDelete = (row:any) => {
    service.drug_delete({ id: row.id}).then((res) => {
      console.log(res)
    })
    setTimeout(() => {
      navigate(0)
  }, 1000)
  }
      const columns= [
        {
          title: '序号',
          dataIndex: 'id',
          key: 'id',
        
        },
        {
          title: '列表图',
          dataIndex:'text',
          key:'text',
          render: (text:any) => {
            return (
              <>
                 <img src={text} alt="" />
              </>
            
           )
         
     }
        },
        {
          title: '药品标题',
          dataIndex: 'drugtitle',
          key: 'drugtitle',
        },
        {
          title: '药品分类',
          dataIndex: 'drugkind',
          key: 'drugkind',
        },
        {
          title: '发布人',
          dataIndex: 'person',
          key: 'person',
        },
        {
          title: '发布状态',
          dataIndex: 'pbulishStasus',
          key: 'pbulishStasus',
        },
        {
          title: '收藏量',
          dataIndex: 'collaction',
          key: 'collaction',
        },
        {
          title: '操作时间',
          dataIndex: 'endingtime',
          key: 'endingtime',
        },
   
        {
          title: '操作',
          
            render: (_: any, row: any) => {
                return (
                  <>
                    
                 <span style={{marginRight:10,color:'blue'}}>编辑</span>
                    <span style={{ color: 'red' }} onClick={()=>{myDelete(row)}} >删除</span>
                </>
             )
         }
        },
       
       
       
  ];
 
    return (
        <div className='system-drug'>
            <h4>药品管理</h4>
            <div className='drug-header'>
                
                <TimeList></TimeList>
                <Button type="primary" >
          发布药品消息
        </Button>
            </div>
            <Table columns={columns} dataSource={data} rowKey="id"  />

            
        </div>
    );
}

export default SystemDrug;